package com.zyl.pts.web.controller;

import com.zyl.pts.config.anno.SystemLog;
import com.zyl.pts.config.enums.CodeAndMessageEnum;
import com.zyl.pts.config.result.Result;
import com.zyl.pts.service.UploadService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @version v1.0
 * @ProjectName: product_source
 * @Package: com.zyl.pts.web.controller
 * @ClassName: UploadController
 * @Description TODO(文件上传模块)
 * @Author 翟玉龙
 * @Date 2024/11/20-15:20
 */
@Tag(name = "文件上传模块", description = "文件上传模块")
@RestController
@RequestMapping("/file")
public class UploadController {

    private final UploadService uploadService;

    public UploadController(UploadService uploadService) {
        this.uploadService = uploadService;
    }

    /**
     * 文件上传接口
     * @param file 上传的文件
     * @return {@link Result }<{@link ? }>
     */
    @SystemLog(business = "文件上传接口")
    @Operation(summary = "文件上传接口")
    @PostMapping("/upload")
    public Result<?> upload(
            @RequestPart MultipartFile file
    ) {
        return Result.success(
                CodeAndMessageEnum.SUCCESS_FILE_UPLOAD,
                uploadService.upload(file)
        );
    }

}
